<!DOCTYPE html>
<html lang="en" class="x-admin-sm" xmlns:th="http://www.thymeleaf.org" >
<head>
    <meta charset="UTF-8">
    <title>关于我的故事</title>
    <header th:replace="header::html"></header>
    <link th:href="@{/xadmin/lib/layui/css/layui.css}" rel="stylesheet" type="text/css"/>
    <script th:src="@{/xadmin/lib/layui/layui.js}" type="text/javascript"></script>
</head>

<body>

    <div class="layui-fluid">
        <div class="layui-row  layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form  layui-col-space5">
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="scontent" id="scontent" placeholder="请输入故事内容关键字" autocomplete="off"
                                       class="layui-input">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="stitle" id="stitle" placeholder="请输入标题关键字" autocomplete="off"
                                       class="layui-input">
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input type="text" class="layui-input" id="startDate" placeholder="请选择开始日期"
                                           name="startDate">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input type="text" class="layui-input" id="endDate" placeholder="请选择结束日期" name="endDate">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <select name="storySticky" id="storySticky" class="layui-select">
                                        <option value="" selected="selected">--置顶状态--</option>
                                        <option value="0">未置顶</option>
                                        <option value="1">已置顶</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <select name="storyStatus" id="storyStatus" class="layui-select">
                                        <option value="" selected="selected">--审核状态--</option>
                                        <option value="0">审核中</option>
                                        <option value="1">审核通过</option>
                                        <option value="2">审核未通过</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-submit="" lay-filter="search"><i
                                        class="layui-icon">&#xe615;</i></button>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-body ">
                        <table class="layui-hide" id="storyTable" lay-filter="storyTable" ></table>
                    </div>
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="delete" >删除</a>
                        {{#  if(d.sstatus ==='2'){ }}
                        <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="resubmit" >重新提交</a>
                        {{#  } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</body>
<script>

	layui.use('laydate', function () {
		var laydate = layui.laydate;
		//选中后的回调
		laydate.render({
			elem: '#startDate'
			, done: function (value, date) {
				// layer.alert('你选择的日期是：' + value + '<br>获得的对象是' + JSON.stringify(date));
			}
		});

		laydate.render({
			elem: '#endDate'
			, done: function (value, date) {
				// layer.alert('你选择的日期是：' + value + '<br>获得的对象是' + JSON.stringify(date));
			}
		});
	});


	layui.use(['table','layer','form'], function () {
		var table = layui.table,
            layer=layui.layer,
			form = layui.form;
		layer.msg('点击表格显示不全内容，可以查看具体内容详情',{icon:6});
		table.render({
			elem: '#storyTable'
			, url: '/api-front/story/myStoryList' //数据接口
			, page: true //开启分页
			, cellMinWidth: 80 //全局定义常规单元格的最小宽度
			, limits:[10,20]
			,limit:10
			, response: {
				dataName: 'datas' //规定数据列表的字段名称，默认：data
			}
			, cols: [
				[
					{type:'numbers' ,align:'center'}
					,{field:'usid', align:'center',title: '雇主故事id',style:'display:none;'}
					,{field:'stitle', title: '故事标题', width:'20%',align:'center',event:'coltitle'}
					,{field:'scontent', width:'37%',align:'center',title: '故事内容',event:'coldetails'}
					,{field:'stime', width:'10%',align:'center', title: '发布时间'}
					,{field:'sstatus', align:'center', title: '审核状态',width: '7%',templet:function (msg) {
						if (msg.sstatus==='0')
						return "审核中"
                        else if (msg.sstatus==='1')
                        return "已通过"
                        else
                        return "未通过"
					}}
					,{field:'ssticky', align:'center', title: '置顶状态',width: '7%',templet:function (msg) {
						return msg.ssticky== '1'?"已置顶":"未置顶";
					}}
					,{ fixed: 'right', title: '操作',  align: 'center',width: 180, toolbar: '#barDemo'}
				]
			],
			done: function () {
				//checkPermission();
			}
		});

		$('table.layui-table thead tr th:eq(1)').addClass('layui-hide');//隐藏的曝光表id表头
		//监听行工具事件
		table.on('tool(storyTable)', function(obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
			var data = obj.data ,//获得当前行数据
				layEvent = obj.event, //获得 lay-event 对应的值
				sid=data.usid,
                content=data.scontent,
                stitle=data.stitle;
			if(layEvent === 'delete') {
				layer.confirm('确定要删除该条故事吗？删除后不可恢复',function (index) {
					$.ajax({
						type:"post",
						url:'/api-front/story/story-delete',
						data:{"sid":sid},
						success:function (msg) {
							if (msg === "success") {
								layer.msg("删除成功",{icon:1});
								$(".layui-laypage-btn")[0].click();
							} else {
								layer.msg("删除失败，请重试",{icon:2})
							}
						},
						error:function (msg) {
							layer.msg("连接服务器超时，请稍后重试",{icon:2})
						}
					})
				})
			}
			else if(layEvent === 'resubmit'){
				layer.confirm('确定重新提交吗？',function (index) {
					$.ajax({
						url:'/api-front/story/story-resubmit',
						type:"post",
						data:{"sid":sid},
						success:function (msg) {
							if (msg === "success") {
								layer.msg("重新提交成功，待管理员审核",{icon:1});
								$(".layui-laypage-btn")[0].click();
							} else {
								layer.msg("重新提交失败，请重试",{icon:2})
							}
						},
						error:function (msg) {
							layer.msg("连接服务器超时，请稍后重试",{icon:2})
						}
					})
				})
			}
			else if(layEvent === 'coldetails'){
				layer.alert(content)
			}
			else if(layEvent === 'coltitle'){
				layer.alert(stitle)
			}
		});

		//搜索
		form.on('submit(search)', function (data) {
			var field = data.field;
			if (dateCompare(field.startDate, field.endDate)) {
				table.render({
					elem: '#storyTable'
					, url: '/api-front/story/myStoryList' //数据接口
					, page: true //开启分页
					, limits:[10,20]
                    ,limit:10
					, where: {
						"scontent": field.scontent,
						"starttime": field.startDate,
						"endtime": field.endDate,
						"stitle": field.stitle,
                        "storySticky":field.storySticky,
						"storyStatus":field.storyStatus
					}
					, response: {
						dataName: 'datas' //规定数据列表的字段名称，默认：data
					}
					, cols: [
						[
							{type:'numbers' ,align:'center'}
							,{field:'usid', align:'center',title: '雇主故事id',style:'display:none;'}
							,{field:'stitle', title: '故事标题', width:'20%',align:'center',event:'coltitle'}
							,{field:'scontent', width:'37%',align:'center',title: '故事内容',event:'coldetails'}
							,{field:'stime', width:'10%',align:'center', title: '发布时间'}
							,{field:'sstatus', align:'center', title: '审核状态',width: '7%',templet:function (msg) {
								if (msg.sstatus==='0')
									return "审核中"
								else if (msg.sstatus==='1')
									return "已通过"
								else
									return "未通过"
							}}
							,{field:'ssticky', align:'center', title: '置顶状态',width: '7%',templet:function (msg) {
								return msg.ssticky== '1'?"已置顶":"未置顶";
							}}
							,{ fixed: 'right', title: '操作',  align: 'center',width: 180, toolbar: '#barDemo'}
						]
					]
				});
				$('table.layui-table thead tr th:eq(1)').addClass('layui-hide');//隐藏的曝光表id表头
			} else {
				layer.msg("您的日期不正确，请重新输入！",{icon:2});
			}
			return false;
		});
		//checkPermission();
	});

	function dateCompare(startDate, endDate) {
		var oDate1 = new Date(startDate);
		var oDate2 = new Date(endDate);
		if (oDate1 > oDate2) {
			return false;
		} else {
			return true;
		}
	}

</script>
</html>